#!/bin/bash
#====================================================
#	SCRIPT:   DARKSSH MANAGER
#	DESENVOLVIDO POR:	CRAZY_VPN
#	CONTATO TELEGRAM:	http://t.me/crazy_vpn
#	contact me:	http://t.me/sibatro
#====================================================
IP=$(cat /etc/IP)
cor1='\033[41;1;37m'
cor2='\033[44;1;37m'
scor='\033[0m'
# Gerar client.ovpn
newclient() {
    cp /etc/openvpn/client-common.txt ~/$1.ovpn
    echo "<ca>" >>~/$1.ovpn
    cat /etc/openvpn/easy-rsa/pki/ca.crt >>~/$1.ovpn
    echo "</ca>" >>~/$1.ovpn
    echo "<cert>" >>~/$1.ovpn
    cat /etc/openvpn/easy-rsa/pki/issued/$1.crt >>~/$1.ovpn
    echo "</cert>" >>~/$1.ovpn
    echo "<key>" >>~/$1.ovpn
    cat /etc/openvpn/easy-rsa/pki/private/$1.key >>~/$1.ovpn
    echo "</key>" >>~/$1.ovpn
    echo "<tls-auth>" >>~/$1.ovpn
    cat /etc/openvpn/ta.key >>~/$1.ovpn
    echo "</tls-auth>" >>~/$1.ovpn
}
fun_geraovpn() {
    [[ "$respost" = @(s|S) ]] && {
        cd /etc/openvpn/easy-rsa/
        ./easyrsa build-client-full $username nopass
        newclient "$username"
        sed -e "s;auth-user-pass;<auth-user-pass>\n$username\n$password\n</auth-user-pass>;g" /root/$username.ovpn >/root/tmp.ovpn && mv -f /root/tmp.ovpn /root/$username.ovpn
    } || {
        cd /etc/openvpn/easy-rsa/
        ./easyrsa build-client-full $username nopass
        newclient "$username"
    }
} >/dev/null 2>&1
[[ -e /etc/openvpn/server.conf ]] && {
    _Port=$(grep -w 'port' /etc/openvpn/server.conf | awk {'print $2'})
    _portarq=$(sed -n '7 p' /etc/openvpn/client-common.txt|cut -d' ' -f3)
    hst=$(sed -n '8 p' /etc/openvpn/client-common.txt | awk {'print $4'})
    rmt=$(sed -n '7 p' /etc/openvpn/client-common.txt)
    hedr=$(sed -n '8 p' /etc/openvpn/client-common.txt)
    prxy=$(sed -n '9 p' /etc/openvpn/client-common.txt)
    rmt2='/SSHPLUS?'
    payload1='#payload "HTTP/1.1 [lf]CONNECT HTTP/1.1[lf][lf]|[lf]."'
    payload2='#payload "CONNECT 127.0.0.1:1194[split][crlf] HTTP/1.0 [crlf][crlf]#"'
    oi="d1n212ccp6ldpw.cloudfront.net"
    bypass="net_gateway"
    slowdns="2222"
    cert01="/etc/openvpn/client-common.txt"
    if [[ "$hst" == "$oi" ]]; then
        Host="Oi"
    elif [[ "$_portarq" == "$slowdns" ]]; then
        Host="MODO SLOWDNS"
    elif [[ "$hst" == "$bypass" ]]; then
        Host="MODO BYPASS"
    elif [[ "$hedr" == "$payload1" ]]; then
        Host="OPEN SOCKS"
    elif [[ "$hedr" == "$payload2" ]]; then
        Host="OPEN SQUID"
    else
        Host="CUSTOM"
    fi
}
fun_bar() {
    comando[0]="$1"
    comando[1]="$2"
    (
        [[ -e $HOME/fim ]] && rm $HOME/fim
        ${comando[0]} >/dev/null 2>&1
        ${comando[1]} >/dev/null 2>&1
        touch $HOME/fim
    ) >/dev/null 2>&1 &
    tput civis
    echo -ne "\033[1;33mHOLD \033[1;37m- \033[1;33m["
    while true; do
        for ((i = 0; i < 18; i++)); do
            echo -ne "\033[1;31m#"
            sleep 0.1s
        done
        [[ -e $HOME/fim ]] && rm $HOME/fim && break
        echo -e "\033[1;33m]"
        sleep 1s
        tput cuu1
        tput dl1
        echo -ne "\033[1;33mHOLD \033[1;37m- \033[1;33m["
    done
    echo -e "\033[1;33m]\033[1;37m -\033[1;32m OK !\033[1;37m"
    tput cnorm
}
fun_edithost() {
    clear
    echo -e "\E[44;1;37m          CHANGE OVPN MODE            \E[0m"
    echo ""
    echo -e "\033[1;33mMODE IN USE\033[1;37m: \033[1;32m$Host"
    echo ""
    echo -e "\033[1;31m[\033[1;36m1\033[1;31m] \033[1;33mOPEN SOCKS \033[1;31m[\033[1;32mAPP MOD\033[1;31m]"
    echo -e "\033[1;31m[\033[1;36m2\033[1;31m] \033[1;33mOPEN SQUID \033[1;31m[\033[1;32mAPP MOD\033[1;31m]"
    echo -e "\033[1;31m[\033[1;36m3\033[1;31m] \033[1;33mSLOWDNS \033[1;31m[\033[1;32mOPENVPN FOR ANDROID + TERMUX\033[1;31m]"
    echo -e "\033[1;31m[\033[1;36m4\033[1;31m] \033[1;33mBYPASS \033[1;31m[\033[1;32mOPENVPN + INJECTOR\033[1;31m]"
    echo -e "\033[1;31m[\033[1;36m5\033[1;31m] \033[1;33mTODOS MODOS \033[1;31m[\033[1;32m1 OVPN DE CADA\033[1;31m]"
    echo -e "\033[1;31m[\033[1;36m6\033[1;31m] \033[1;33mEDIT MANUALLY"
    echo -e "\033[1;31m[\033[1;36m0\033[1;31m] \033[1;33mRETURN"
    echo ""
    echo -ne "\033[1;32mWHICH MODE YOU WANT TO USE \033[1;33m?\033[1;37m "
    read respo
    [[ -z "$respo" ]] && {
        echo -e "\n\033[1;31mInvalid option!"
        sleep 2
        fun_edithost
    }
    if [[ "$respo" = '1' ]]; then
        echo -e "\n\033[1;32mCHANGING MODE!\033[0m\n"
        fun_althostpay1() {
        	sed -i "7,9"d $cert01
        	sleep 1
        	sed -i "7i\remote $rmt2 $_Port\n$payload1\nhttp-proxy $IP 8080" $cert01
        }
        fun_bar 'fun_althostpay1'
        echo -e "\n\033[1;32mSUCCESSFULLY CHANGED MODE!\033[0m"
        fun_geraovpn
        sleep 1.5
    elif [[ "$respo" = '2' ]]; then
        echo -e "\n\033[1;32mCHANGING MODE!\033[0m\n"
        fun_althostpay2() {
            sed -i "7,9"d $cert01
        	sleep 1
        	sed -i "7i\remote $rmt2 $_Port\n$payload2\nhttp-proxy $IP 80" $cert01
        }
        fun_bar 'fun_althostpay2'
        echo -e "\n\033[1;32mSUCCESSFULLY CHANGED MODE!\033[0m"
        fun_geraovpn
        sleep 1.5
    elif [[ "$respo" = '3' ]]; then
        echo -e "\n\033[1;32mCHANGING MODE!\033[0m\n"
        fun_althost5() {
        	sed -i "7,9"d $cert01
        	sleep 1
        	sed -i "7i\remote 127.0.0.1 2222\nroute $IP 255.255.255.255 net_gateway" $cert01
        }
        fun_bar 'fun_althost5'
        echo -e "\n\033[1;32mSUCCESSFULLY CHANGED MODE!\033[0m"
        fun_geraovpn
        sleep 1.5
    elif [[ "$respo" = '4' ]]; then
        echo -e "\n\033[1;32mCHANGING MODE!\033[0m\n"
        fun_althost6() {
        	sed -i "7,9"d $cert01
        	sleep 1
        	sed -i "7i\remote $IP $_Port\nroute $IP 255.255.255.255 net_gateway\nhttp-proxy 127.0.0.1 8989" $cert01
        }
        fun_bar 'fun_althost6'
        echo -e "\n\033[1;32mSUCCESSFULLY CHANGED MODE!\033[0m"
        fun_geraovpn
        sleep 1.5
    elif [[ "$respo" = '5' ]]; then
        [[ ! -e "$HOME/$username.ovpn" ]] && fun_geraovpn
        echo -e "\n\033[1;32mCHANGING MODE!\033[0m\n"
        fun_packhost() {
            [[ ! -d "$HOME/OVPN" ]] && mkdir $HOME/OVPN
            sed -i "7,9"d $HOME/$username.ovpn
            sleep 0.5
            sed -i "7i\remote $IP $_Port\nroute $IP 255.255.255.255 net_gateway\nhttp-proxy 127.0.0.1 8989" $HOME/$username.ovpn
            cp $HOME/$username.ovpn /root/OVPN/$username-bypass.ovpn
			sed -i "7,9"d $HOME/$username.ovpn
			sleep 0.5
            sed -i "7i\remote 127.0.0.1 2222\nroute $IP 255.255.255.255 net_gatewaY" $HOME/$username.ovpn
            cp $HOME/$username.ovpn /root/OVPN/$username-slowdns.ovpn
			sed -i "7,9"d $HOME/$username.ovpn
			sleep 0.5
			sed -i "7i\remote $rmt2 $_Port\n$payload1\nhttp-proxy $IP 8080" $HOME/$username.ovpn
            cp $HOME/$username.ovpn /root/OVPN/$username-socks.ovpn
			sed -i "7,9"d $HOME/$username.ovpn
			sleep 0.5
			sed -i "7i\remote $rmt2 $_Port\n$payload2\nhttp-proxy $IP 80" $HOME/$username.ovpn
            cp $HOME/$username.ovpn /root/OVPN/$username-squid.ovpn
            cd $HOME/OVPN && zip $username.zip *.ovpn >/dev/null 2>&1 && cp $username.zip $HOME/$username.zip
            cd $HOME && rm -rf /root/OVPN >/dev/null 2>&1
        }
        fun_bar 'fun_packhost'
        echo -e "\n\033[1;32mSUCCESSFULLY CHANGED MODE!\033[0m"
        sleep 1.5
    elif [[ "$respo" = '6' ]]; then
        echo ""
        echo -e "\033[1;32mCHANGING OVPN FILE!\033[0m"
        echo ""
        echo -e "\033[1;31mATTENTION!\033[0m"
        echo ""
        echo -e "\033[1;33mTO SAVE USE KEYS \033[1;32mctrl x y\033[0m"
        sleep 4
        clear
        nano /etc/openvpn/client-common.txt
        echo ""
        echo -e "\033[1;32mSUCCESSFULLY CHANGED!\033[0m"
        fun_geraovpn
        sleep 1.5
    elif [[ "$respo" = '0' ]]; then
        echo ""
        echo -e "\033[1;31mReturning...\033[0m"
        sleep 2
    else
        echo ""
        echo -e "\033[1;31mInvalid option !\033[0m"
        sleep 2
        fun_edithost
    fi
}
[[ ! -e /usr/lib/sshplus ]] && exit 0
tput setaf 7;tput setab 4;tput bold;printf '%30s%s%-15s\n' "Create SSH User";tput sgr0
echo ""
echo "===================================================="
echo -e "\033[0;34m  #BY:      🔥⚡️⚡️ Sithum Batrow 🇱🇰 ⚡️⚡️🔥         \E[0m"
echo "===================================================="
echo ""
echo -ne "\033[1;32mUsername:\033[1;37m ";read username
[[ -z $username ]] && {
	echo -e "\n${cor1}Empty or invalid username!${scor}\n"
	exit 1
}
[[ "$(grep -wc $username /etc/passwd)" != '0' ]] && {
	echo -e "\n${cor1}This user already exists. try another name!${scor}\n"
	exit 1
}
[[ ${username} != ?(+|-)+([a-zA-Z0-9]) ]] && {
	echo -e "\n${cor1}You have entered an invalid username!${scor}"
	echo -e "${cor1}Do not use spaces, accents or special characters!${scor}\n"
	exit 1
}
sizemin=$(echo ${#username})
[[ $sizemin -lt 2 ]] && {
	echo -e "\n${cor1}You entered a very short username${scor}"
	echo -e "${cor1}use at least two characters!${scor}\n"
	exit 1
}
sizemax=$(echo ${#username})
[[ $sizemax -gt 10 ]] && {
	echo -e "\n${cor1}You entered a very long username"
	echo -e "${cor1}use a maximum of 10 characters!${scor}\n"
	exit 1
}
echo -ne "\033[1;32mPassword:\033[1;37m ";read password
[[ -z $password ]] && {
	echo -e "\n${cor1}Password empty or invalid!${scor}\n"
	exit 1
}
sizepass=$(echo ${#password})
[[ $sizepass -lt 4 ]] && {
	echo -e "\n${cor1}Short password !, use at least 4 characters${scor}\n"
	exit 1
}
echo -ne "\033[1;32mDays to expire:\033[1;37m ";read dias
[[ -z $dias ]] && {
	echo -e "\n${cor1}Number of days empty!${scor}\n"
	exit 1
}
[[ ${dias} != ?(+|-)+([0-9]) ]] && {
	echo -e "\n${cor1}You have entered an invalid number of days!${scor}\n"
	exit 1
}
[[ $dias -lt 1 ]] && {
	echo -e "\n${cor1}The number must be greater than zero!${scor}\n"
	exit 1
}
echo -ne "\033[1;32mConnection limit:\033[1;37m ";read sshlimiter
[[ -z $sshlimiter ]] && {
	echo -e "\n${cor1}You left the connection limit empty!${scor}\n"
	exit 1
}
[[ ${sshlimiter} != ?(+|-)+([0-9]) ]] && {
	echo -e "\n${cor1}You have entered an invalid connection number!${scor}\n"
	exit 1
}
[[ $sshlimiter -lt 1 ]] && {
	echo -e "\n${cor1}Number of simultaneous connections must be greater than zero!${scor}\n"
	exit 1	
}
echo -ne "\033[1;32mBaner-Name:\033[1;37m ";read banername
[[ -z $banername ]] && {
	echo -e "\n${cor1}Empty or invalid banername!${scor}\n"
	
}	

final=$(date "+%Y-%m-%d" -d "+$dias days")
gui=$(date "+%d/%m/%Y" -d "+$dias days")
pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
useradd -e $final -M -s /bin/false -p $pass $username >/dev/null 2>&1 &
echo "$password" >/etc/SSHPlus/senha/$username
echo "$username $sshlimiter" >>/root/usuarios.db
[[ -e /etc/openvpn/server.conf ]] && {
	echo -ne "\033[1;32mGenerate Ovpn File \033[1;31m? \033[1;33m[s/n]:\033[1;37m "; read resp
	[[ "$resp" = @(s|S) ]] && {
		rm $username.zip $username.ovpn >/dev/null 2>&1
		echo -ne "\033[1;32mGenerate With username and password \033[1;31m? \033[1;33m[s/n]:\033[1;37m "
		read respost
		echo -ne "\033[1;32mModo Atual\033[1;37m: \033[1;31m(\033[1;37m$Host\033[1;31m) \033[1;37m- \033[1;32mAlterar \033[1;31m? \033[1;33m[s/n]:\033[1;37m "; read oprc
		[[ "$oprc" = @(s|S) ]] && {
			fun_edithost
		} || {
			fun_geraovpn
		}
		gerarovpn() {
			[[ ! -e "/root/$username.zip" ]] && {
				zip /root/$username.zip /root/$username.ovpn
				sleep 1.5
			}
		}
		clear
		echo -e "\E[44;1;37m      SSH ACCOUNT CREATED!      \E[0m"
		echo ""
                echo -e "\033[1;32m♻️Paid Privet SSH ♻️"
                echo ""
                echo -e "\033[1;32m$banername"
                echo -e "\033[1;32m======================"
                echo -e "\033[1;32m=❌NO SPAM"
                echo -e "\033[1;32m=❌NO DDOS "
                echo -e "\033[1;32m=❌NO HACKING "
                echo -e "\033[1;32m=❌NO CARDING   "
                echo -e "\033[1;32m=❌NO TORRENT   "
                echo -e "\033[1;32m=❌NO OVER DOWNLOAD"
                echo -e "\033[1;32m=❌NO MULTILOGIN "
                echo -e "\033[1;32m======================="
                echo ""
		echo -e "\n\033[1;32mᗚ IP • ๛ \033[1;37m$IP"
		echo -e "\033[1;32mᗚ Username • ๛ \033[1;37m$username"
		echo -e "\033[1;32mᗚ Password • ๛ \033[1;37m$password"
		echo -e "\033[1;32mᗚ Expire • \033[1;37m$gui"
		echo -e "\033[1;32mᗚ Limit • \033[1;37m$sshlimiter"
		echo ""
                echo -e "\033[1;32m࿂ SSH •  22"
                echo -e "\033[1;32m࿂ SSL •  443"
                echo -e "\033[1;32m࿂ Squid  •  8080"
                echo -e "\033[1;32m࿂ Dropbear •  80"
                echo -e "\033[1;32m [-] ═───────◇───────═"
                echo -e "\033[1;32m࿂ Badvpn •  7300"
                echo -e "\033[1;32m [-] ═───────◇───────═"
                echo -e "\033[1;32m›☬[•] SCRIPTS ═◇ DARKSSH ◇═ [•]☬"
		sleep 1
		function aguarde() {
			helice() {
				gerarovpn >/dev/null 2>&1 &
				tput civis
				while [ -d /proc/$! ]; do
					for i in / - \\ \|; do
						sleep .1
						echo -ne "\e[1D$i"
					done
				done
				tput cnorm
			}
			echo ""
			echo -ne "\033[1;31mCREATING OVPN\033[1;33m.\033[1;31m. \033[1;32m"
			helice
			echo -e "\e[1DOK"
		}
		aguarde
		VERSION_ID=$(cat /etc/os-release | grep "VERSION_ID")
		echo ""
		[[ -d /var/www/html/openvpn ]] && {
			mv $HOME/$username.zip /var/www/html/openvpn/$username.zip >/dev/null 2>&1
			[[ "$VERSION_ID" = 'VERSION_ID="14.04"' ]] && {
				echo -e "\033[1;32mLINK\033[1;37m: \033[1;36m$IP:81/html/openvpn/$username.zip"
			} || {
				echo -e "\033[1;32mLINK\033[1;37m: \033[1;36m$IP:81/openvpn/$username.zip"
			}
		} || {
			echo -e "\033[1;32mDisponivel em\033[1;31m" ~/"$username.zip\033[0m"
			sleep 1
		}
	} || {
		clear
		echo -e "\E[44;1;37m       SSH ACCOUNT CREATED!      \E[0m"
		echo ""
		echo -e "\033[1;32m♻️Paid Privet SSH ♻️"
                echo ""
                echo -e "\033[1;32m$banername"
                echo -e "\033[1;32m======================"
                echo -e "\033[1;32m=❌NO SPAM"
                echo -e "\033[1;32m=❌NO DDOS "
                echo -e "\033[1;32m=❌NO HACKING "
                echo -e "\033[1;32m=❌NO CARDING   "
                echo -e "\033[1;32m=❌NO TORRENT   "
                echo -e "\033[1;32m=❌NO OVER DOWNLOAD"
                echo -e "\033[1;32m=❌NO MULTILOGIN "
                echo -e "\033[1;32m======================="
                echo ""
		echo -e "\n\033[1;32mᗚ IP • ๛ \033[1;37m$IP"
		echo -e "\033[1;32mᗚ Username • ๛ \033[1;37m$username"
		echo -e "\033[1;32mᗚ Password • ๛ \033[1;37m$password"
		echo -e "\033[1;32mᗚ Expire • \033[1;37m$gui"
		echo -e "\033[1;32mᗚ Limit • \033[1;37m$sshlimiter"
		echo ""
                echo -e "\033[1;32m࿂ SSH •  22"
                echo -e "\033[1;32m࿂ SSL •  443"
                echo -e "\033[1;32m࿂ Squid  •  8080"
                echo -e "\033[1;32m࿂ Dropbear •  80"
                echo -e "\033[1;32m [-] ═───────◇───────═"
                echo -e "\033[1;32m࿂ Badvpn •  7300"
                echo -e "\033[1;32m [-] ═───────◇───────═"
                echo -e "\033[1;32m›☬[•] SCRIPTS ═◇ DARKSSH ◇═ [•]☬"
		
	}
} || {
	clear
	echo -e "\E[44;1;37m       SSH ACCOUNT CREATED!      \E[0m"
	echo ""
	echo -e "\033[1;32m♻️Paid Privet SSH ♻️"
        echo ""
        echo -e "\033[1;32m$banername"
        echo -e "\033[1;32m======================"
        echo -e "\033[1;32m=❌NO SPAM"
        echo -e "\033[1;32m=❌NO DDOS "
        echo -e "\033[1;32m=❌NO HACKING "
        echo -e "\033[1;32m=❌NO CARDING   "
        echo -e "\033[1;32m=❌NO TORRENT   "
        echo -e "\033[1;32m=❌NO OVER DOWNLOAD"
        echo -e "\033[1;32m=❌NO MULTILOGIN "
        echo -e "\033[1;32m======================="
        echo ""
	echo -e "\n\033[1;32mᗚ IP • ๛ \033[1;37m$IP"
	echo -e "\033[1;32mᗚ Username • ๛ \033[1;37m$username"
	echo -e "\033[1;32mᗚ Password • ๛ \033[1;37m$password"
	echo -e "\033[1;32mᗚ Expire • \033[1;37m$gui"
        echo -e "\033[1;32mᗚ Limit • \033[1;37m$sshlimiter"
        echo ""
        echo -e "\033[1;32m࿂ SSH •  22"
        echo -e "\033[1;32m࿂ SSL •  443"
        echo -e "\033[1;32m࿂ Squid  •  8080"
        echo -e "\033[1;32m࿂ Dropbear •  80"
        echo -e "\033[1;32m [-] ═───────◇───────═"
        echo -e "\033[1;32m࿂ Badvpn •  7300"
        echo -e "\033[1;32m [-] ═───────◇───────═"
        echo -e "\033[1;32m›☬[•] SCRIPTS ═◇ DARKSSH ◇═ [•]☬"
	
}
